package com.willian.andrappfw.utils;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;

public class HandlerUtil {
    private static Handler mainLooperHandler;
    private static Handler subThreadHandler;
    private static Thread thread;

    public HandlerUtil() {
    }

    public static synchronized void init(Context context) {
        if (thread == null) {
            thread = new Thread(() -> {
                Looper.prepare();
                subThreadHandler = new Handler();
                Looper.loop();
            });
            thread.start();
        }

        mainLooperHandler = new Handler(context.getMainLooper());
    }

    public static Handler getMainLooperHandler() {
        return mainLooperHandler;
    }

    public static Handler getSubThreadHandler() {
        return subThreadHandler;
    }
}

